package com.zcm.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.zcm.entity.u_order;
import com.zcm.entity.shopping_cart;
import com.zcm.entity.user;

/**
 * Servlet implementation class DoAddShoppingCart
 */
@WebServlet("/DOAddTest")
public class DoAddTest extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoAddTest() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		Configuration cfg=new Configuration().configure();
		SessionFactory factory=cfg.buildSessionFactory();
		Session session=factory.openSession();
		Transaction tran=session.beginTransaction();
		
//		Integer.parseInt(request.getParameter("xxx"));
		
		
		
		//代码仅测试添加商品功能是否实现，不作为实际servlet使用
		
		int a =3 ;
		int b =4;
		u_order sc =new u_order();
		//这是购物车的功能
//		sc.setComid(a);
//		sc.setUserid(b);
		//这是订单信息功能
		sc.setCategory("asd");
		sc.setColor("red");
		sc.setCom_name("aaaa");
		sc.setComid(1);
		sc.setPrince(33.2);
		sc.setSize("L");
		sc.setUserid(1);
		session.save(sc);
		tran.commit();
		session.close();
		factory.close();
		request.getRequestDispatcher("/login.jsp").forward(request, response);	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
